package com.lb.jwitter.action.report;


import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import com.lb.jwitter.service.ConditionReport;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocChiTiet;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocChiTietService;
import com.lb.jwitter.service.TblQLDTTXADMChiNhanh;
import com.lb.jwitter.service.TblQLDTTXADMChiNhanhService;
import com.lb.jwitter.service.TblQLDTTXADMKhoa;
import com.lb.jwitter.service.TblQLDTTXADMKhoaHoc;
import com.lb.jwitter.service.TblQLDTTXADMKhoaHocService;
import com.lb.jwitter.service.TblQLDTTXADMKhoaService;
import com.lb.jwitter.service.TblQLDTTXADMNganh;
import com.lb.jwitter.service.TblQLDTTXADMNganhService;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNam;
import com.lb.jwitter.service.TblQLDTTXAHocKyTrongNamService;
import com.lb.jwitter.service.TblQLDTTXAHocVien;
import com.lb.jwitter.service.TblQLDTTXAHocVienChuongTrinhHoc;
import com.lb.jwitter.service.TblQLDTTXAHocVienChuongTrinhHocService;
import com.lb.jwitter.service.TblQLDTTXAHocVienDonXinXetMienGiam;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiBienLai;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiBienLaiService;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiMonHoc;
import com.lb.jwitter.service.TblQLDTTXAHocVienHocPhiMonHocService;
import com.lb.jwitter.service.TblQLDTTXAHocVienMienGiam;
import com.lb.jwitter.service.TblQLDTTXAHocVienMienGiamService;
import com.lb.jwitter.service.TblQLDTTXAHocVienService;
import com.lb.jwitter.service.TblQLDTTXAMonHoc;
import com.lb.jwitter.service.TblQLDTTXAQuiDinhHocPhi;
import com.lb.jwitter.service.TblQLDTTXAQuiDinhHocPhiService;
import com.lb.jwitter.service.TblQuyenChiTietService;
import com.lb.jwitter.service.TblTaiKhoan;
import com.lb.jwitter.util.ApplicationContextProvider;
import com.lb.jwitter.util.Message;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAHocVienTinhTrangHocPhiReportAction{
    private Message msg; 
    public Message getMsg() { return msg; }

   
    private Long hocKyId;
    
    private Long khoaId;
    private Long nganhId;
    private Long khoaHocId;
    private Long chiNhanhId;
    
    private String report;    
    
    private TblQLDTTXAHocKyTrongNamService tblQLDTTXAHocKyTrongNamService;
    
    
    private TblQLDTTXAHocVienMienGiamService tblQLDTTXAHocVienMienGiamService;
    private TblQLDTTXAChuongTrinhHocChiTietService tblQLDTTXAChuongTrinhHocChiTietService;
    private TblQLDTTXAHocVienService tblQLDTTXAHocVienService;
    private TblQLDTTXAHocVienChuongTrinhHocService tblQLDTTXAHocVienChuongTrinhHocService;
    private TblQLDTTXAHocVienHocPhiMonHocService tblQLDTTXAHocVienHocPhiMonHocService;
    private TblQLDTTXAHocVienHocPhiBienLaiService tblQLDTTXAHocVienHocPhiBienLaiService;
    private TblQLDTTXAQuiDinhHocPhiService tblQLDTTXAQuiDinhHocPhiService;
    
    private TblQLDTTXADMKhoaService tblQLDTTXADMKhoaService;
    private TblQLDTTXADMKhoaHocService tblQLDTTXADMKhoaHocService;
    private TblQLDTTXADMNganhService tblQLDTTXADMNganhService;
    private TblQLDTTXADMChiNhanhService tblQLDTTXADMChiNhanhService;
    
    private List<TblQLDTTXADMKhoa> tblQLDTTXADMKhoas;
    private List<TblQLDTTXADMNganh> tblQLDTTXADMNganhs;
    private List<TblQLDTTXADMKhoaHoc> tblQLDTTXADMKhoaHocs;
    private List<TblQLDTTXADMChiNhanh> tblQLDTTXADMChiNhanhs;
    
    
    private List<TblQLDTTXAHocKyTrongNam> tblQLDTTXAHocKyTrongNams;
    private List<TblQLDTTXAChuongTrinhHocChiTiet> tblQLDTTXAChuongTrinhHocChiTiets;
    private List<TblQLDTTXAHocVien> tblQLDTTXAHocViens;


  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String form() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_LopMonHoc_HocVien", "xem")){ 
        return "noprivilege"; 
    } 
 
        //tblQLDTTXADMChiNhanhService = (TblQLDTTXADMChiNhanhService) context.getBean("tbl_QLDTTXA_DM_ChiNhanhClient");
        //tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient");
        tblQLDTTXADMChiNhanhService = (TblQLDTTXADMChiNhanhService) context.getBean("tbl_QLDTTXA_DM_ChiNhanhClient");
        tblQLDTTXADMKhoaHocService = (TblQLDTTXADMKhoaHocService) context.getBean("tbl_QLDTTXA_DM_KhoaHocClient");
        tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DM_KhoaClient");
        tblQLDTTXADMNganhService = (TblQLDTTXADMNganhService) context.getBean("tbl_QLDTTXA_DM_NganhClient");
        
        //        tblQLDTTXAHocVienHocPhiService = (TblQLDTTXAHocVienHocPhiService) context.getBean("tbl_QLDTTXA_HocVien_HocPhiClient"); 


        msg = new Message(); 
        
        tblQLDTTXADMChiNhanhs = tblQLDTTXADMChiNhanhService.findAlltblQLDTTXADMChiNhanh(0, 0);
        tblQLDTTXADMKhoaHocs = tblQLDTTXADMKhoaHocService.findAlltblQLDTTXADMKhoaHoc(20, 1);
        tblQLDTTXADMKhoas = tblQLDTTXADMKhoaService.findAlltblQLDTTXADMKhoa(0, 0);
        tblQLDTTXADMNganhs = tblQLDTTXADMNganhService.findAlltblQLDTTXADMNganh(0, 0);
         
        return Action.SUCCESS;
	 }catch(Exception e){ 
	     System.out.println("Loi Report tblQLDTTXABienNhanHoSo Action"); 
	     e.printStackTrace(); 
	     return Action.ERROR; 
	}
}
 
 
 
 
 public String execute() throws Exception 
 { 
  try{ 	
      Map session = ActionContext.getContext().getSession();
      taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
      if( taiKhoanDangNhap == null) return "noprivilege";
     ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
     tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
     if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_BienNhanHoSo", "xem")){ 
         return "noprivilege"; 
     } 
  
//         tblQLDTTXADMChiNhanhService = (TblQLDTTXADMChiNhanhService) context.getBean("tbl_QLDTTXA_DM_ChiNhanhClient");
//         tblQLDTTXADMKhoaHocService = (TblQLDTTXADMKhoaHocService) context.getBean("tbl_QLDTTXA_DM_KhoaHocClient");
//         tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DMKhoaClient");
//         tblQLDTTXADMNganhService = (TblQLDTTXADMNganhService) context.getBean("tbl_QLDTTXA_DM_NganhClient");
//         tblQLDTTXAHocKyTrongNamService = (TblQLDTTXAHocKyTrongNamService) context.getBean("tbl_QLDTTXA_HocKyTrongNamClient");
         //tblQLDTTXAHocVienDangKyMonHocService = (TblQLDTTXAHocVienDangKyMonHocService) context.getBean("tbl_QLDTTXA_HocVien_DangKyMonHocClient");
         //tblQLDTTXAHocVienPhieuDangKyMonHocService = (TblQLDTTXAHocVienPhieuDangKyMonHocService) context.getBean("tbl_QLDTTXA_HocVien_PhieuDangKyMonHocClient"); 
         //tblQLDTTXALopMonHocDuKienService = (TblQLDTTXALopMonHocDuKienService) context.getBean("tbl_QLDTTXA_LopMonHoc_DuKienClient");
         tblQLDTTXAHocVienMienGiamService = (TblQLDTTXAHocVienMienGiamService) context.getBean("tbl_QLDTTXA_HocVien_MienGiamClient");
         //tblQLDTTXALopMonHocService = (TblQLDTTXALopMonHocService) context.getBean("tbl_QLDTTXA_LopMonHocClient");
         tblQLDTTXAChuongTrinhHocChiTietService = (TblQLDTTXAChuongTrinhHocChiTietService) context.getBean("tbl_QLDTTXA_ChuongTrinhHoc_ChiTietClient");
         tblQLDTTXAHocVienService = (TblQLDTTXAHocVienService) context.getBean("tbl_QLDTTXA_HocVienClient");
         tblQLDTTXAHocVienChuongTrinhHocService = (TblQLDTTXAHocVienChuongTrinhHocService)context.getBean("tbl_QLDTTXA_HocVien_ChuongTrinhHocClient");
         tblQLDTTXAHocVienHocPhiMonHocService = (TblQLDTTXAHocVienHocPhiMonHocService) context.getBean("tbl_QLDTTXA_HocVienHocPhi_MonHocClient");
         tblQLDTTXAHocVienHocPhiBienLaiService = (TblQLDTTXAHocVienHocPhiBienLaiService)context.getBean("tbl_QLDTTXA_HocVien_HocPhi_BienLaiClient");
         //tblQLDTTXAMonHocs = new ArrayList<TblQLDTTXAMonHoc>();
         tblQLDTTXAQuiDinhHocPhiService = (TblQLDTTXAQuiDinhHocPhiService)context.getBean("tbl_QLDTTXA_QuiDinhHocPhiClient");
         
         msg = new Message(); 
         List<ConditionReport> cons = new ArrayList<ConditionReport>();
         
         /*
          * Lay ra cac mon hoc duoc mo trong hoc ky
          */
         cons.clear();
         { 
         	
             ConditionReport con = new ConditionReport(); 
             con.setCol("chuongTrinhHocId.id");
             con.setValue1(new Long(1));
             con.setOperator("eq");
             cons.add(con);	
         }
         tblQLDTTXAChuongTrinhHocChiTiets = tblQLDTTXAChuongTrinhHocChiTietService.findtblQLDTTXAChuongTrinhHocChiTietByCondition(cons, 0, 0);
         
         /*tblQLDTTXAMonHocs = new ArrayList<TblQLDTTXAMonHoc>();
         List<Long> monHocIds = new ArrayList<Long>();
         for(TblQLDTTXALopMonHoc tblLop : tblQLDTTXALopMonHocs){
      	   if(!monHocIds.contains(tblLop.getMonHocId().getId())){
     		   tblQLDTTXAMonHocs.add(tblLop.getMonHocId());
     		   monHocIds.add(tblLop.getMonHocId().getId());
     	   }
         	
         }*/
         
         //lay danh sach hoc vien
         cons.clear();
         { 
             ConditionReport con = new ConditionReport(); 
             con.setCol("trangThaiId.id");
             con.setValue1(new Long(1));
             con.setOperator("eq");
             cons.add(con);	
         }
         if(khoaId != null && !khoaId.equals(new Long(0))){ 
             ConditionReport con = new ConditionReport(); 
             con.setCol("khoaId.id");
             con.setValue1(khoaId);
             con.setOperator("eq");
             cons.add(con);	
         } 
         if(khoaHocId != null && !khoaHocId.equals(new Long(0))){ 
             ConditionReport con = new ConditionReport(); 
             con.setCol("khoaHocId.id");
             con.setValue1(khoaHocId);
             con.setOperator("eq");
             cons.add(con);	
         } 
         if(nganhId != null && !nganhId.equals(new Long(0))){ 
             ConditionReport con = new ConditionReport(); 
             con.setCol("nganhId.id");
             con.setValue1(nganhId);
             con.setOperator("eq");
             cons.add(con);	
         } 
         if(chiNhanhId != null && !chiNhanhId.equals(new Long(0))){ 
             ConditionReport con = new ConditionReport(); 
             con.setCol("chiNhanhId.id");
             con.setValue1(chiNhanhId);
             con.setOperator("eq");
             cons.add(con);	
         } 
         
         { 
             ConditionReport con = new ConditionReport(); 
             con.setCol("ten");
             con.setValue1("asc");
             con.setOperator("order");
             cons.add(con);	
         } 
         
         { 
             ConditionReport con = new ConditionReport(); 
             con.setCol("hoTen");
             con.setValue1("asc");
             con.setOperator("order");
             cons.add(con);	
         } 

         tblQLDTTXAHocViens = tblQLDTTXAHocVienService.findtblQLDTTXAHocVienByCondition(cons, 0, 0);
	      
 		
	     	      
		  //sinh report
		  int colNo = 0;
		  
		  report ="<tbody>";
		  int stt = 0;
		  DecimalFormat myFormatter = new DecimalFormat("###,###.##");
		  
		  int countMonHoc[] = new int[tblQLDTTXAChuongTrinhHocChiTiets.size()];
		  int i;
		  for( i= 0; i < countMonHoc.length; i++){
			  countMonHoc[i] = 0;
		  }
		  
		  Double countHPX = 0.0;
		  Double countHPKM = 0.0;
		  Double countTienMienMon = 0.0;
		  Double countDaDong = 0.0;
		  Double countNo = 0.0;
		  
		  TblQLDTTXAQuiDinhHocPhi quiDinhHocPhi = null;
		  List<TblQLDTTXAQuiDinhHocPhi> tblQLDTTXAQuiDinhHocPhis = tblQLDTTXAQuiDinhHocPhiService.findAlltblQLDTTXAQuiDinhHocPhi(0, 0);
		  if(tblQLDTTXAQuiDinhHocPhis != null && tblQLDTTXAQuiDinhHocPhis.size() > 0){
			  quiDinhHocPhi = tblQLDTTXAQuiDinhHocPhis.get(0);
		  }
		  
		  for(TblQLDTTXAHocVien hocVien : tblQLDTTXAHocViens){ 
			   
			  //DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
		      
		      stt++;
		      report += "<tr class='tableitem' > "; 
		      //stt
		      report += "<TD>" +stt+ "</TD>"; 
		      //mshv
		      report += "<td>" + (hocVien.getMSHV() == null ? "" : hocVien.getMSHV())+ "</td> ";
		      //lop
		      report += "<td>" + (hocVien.getLopId() == null ? "" : hocVien.getLopId().getTen())+ "</td> ";
		      //ho ten
		      report += "<td>" +hocVien.getHoTen()+ "</td> ";
		      report += "<td>" +hocVien.getTen()+ "</td> ";
		      //ngay sinh
		      try{
			      report += "<td>" 
			    	  +hocVien.getHoSoId().getNgaySinh().getDay()+"/"
			    	  +hocVien.getHoSoId().getNgaySinh().getMonth()+"/"
			    	  +hocVien.getHoSoId().getNgaySinh().getYear()+ "</td>";
			      
		      }catch(Exception e){
		    	  report += "<td></td>"; 
		            
		      }
		      
		      cons.clear();
			   { 
			       ConditionReport con = new ConditionReport(); 
			       con.setCol("donMGId.hocVienId.id");
			       con.setValue1(hocVien.getId());
			       con.setOperator("eq");
			       cons.add(con);	
			   } 
			   /*{ 
			       ConditionReport con = new ConditionReport(); 
			       con.setCol("duocMienGiam");
			       con.setValue1(true);
			       con.setOperator("eq");
			       cons.add(con);	
			   } */
			   List<TblQLDTTXAHocVienMienGiam> tblQLDTTXAHocVienMienGiams = tblQLDTTXAHocVienMienGiamService.findtblQLDTTXAHocVienMienGiamByCondition(cons, 0, 0);
			   
			// lay diem so hoc vien tu hocvien_chuongtrinhhoc
		       cons.clear();
			   { 
			       ConditionReport con = new ConditionReport(); 
			       con.setCol("hocVienHocPhiId.hocVienId.id");
			       con.setValue1(hocVien.getId());
			       con.setOperator("eq");
			       cons.add(con);	
			   } 		
			   
			   List<TblQLDTTXAHocVienHocPhiMonHoc> tblQLDTTXAHocVienHocPhiMonHocs = tblQLDTTXAHocVienHocPhiMonHocService.findtblQLDTTXAHocVienHocPhiMonHocByCondition(cons, 0, 0);
			   
		      Double hpX = 0.0;
		      Double hpKM = 0.0;
		      //int tienDongKM = 0;
		      TblQLDTTXAHocVienDonXinXetMienGiam donMienGiam = null;
			   
		      //hoc phi tung mon hoc
		      int j = 0;
		      for(TblQLDTTXAChuongTrinhHocChiTiet chuongTrinhHocChiTiet : tblQLDTTXAChuongTrinhHocChiTiets){
		    	  TblQLDTTXAMonHoc monHoc = chuongTrinhHocChiTiet.getMonHocId();
		    	  //tblQLDTTXAMonHocs.add(monHoc);
			      //Boolean b = false;
			      TblQLDTTXAHocVienMienGiam mienMon = null;
				   //Double hocPhiMonHoc = 0.0;
				   
			       for(TblQLDTTXAHocVienMienGiam mienGiam : tblQLDTTXAHocVienMienGiams){
			    	   if (monHoc.getId().equals(mienGiam.getMonHocId().getId())){
			    		   mienMon = mienGiam;
			    		   break;
			    	   }
			       }
					
			       List<TblQLDTTXAHocVienHocPhiMonHoc> mhs = new ArrayList<TblQLDTTXAHocVienHocPhiMonHoc>();
			       
			       for(TblQLDTTXAHocVienHocPhiMonHoc hpMonHoc : tblQLDTTXAHocVienHocPhiMonHocs){
			    	   if (monHoc.getId().equals(hpMonHoc.getMonHocId().getId())){
			    		   mhs.add(hpMonHoc);
			    	   }
			       }
			       
				   /*if(hvChuongTrinhHocs.size() > 0){
					   tblQLDTTXAHocVienChuongTrinhHoc = hvChuongTrinhHocs.get(0);
				   }*/
			       
				   //}//end for chi tiet hoc phi
				   if(mienMon != null){
					   if(mienMon.isDuocMienGiam()){
						   if(mhs.size() > 0){
							   //report += "<TD>" + mhs.size() + "MM</TD>";							   
							   int countKoMien = 0;
							   for(TblQLDTTXAHocVienHocPhiMonHoc mh : mhs){
								   if (mh.getThanhTien() > 0){
									   hpX += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
									   countMonHoc[j] += 1;
									   countKoMien ++;
								   }
							   }
							   if (countKoMien > 0)
								   report += "<TD>" + countKoMien + "MM</TD>";
							   else
								   report += "<TD>MM</TD>";
						   } else
							   report += "<TD>MM</TD>";
					   }
					   else {
						   if(mienMon.getDonMGId().isTronGoi())
						   {
							   if(mhs.size() > 0){
								   if (mhs.size() == 1)
									   report += "<TD>X</TD>";
								   else
									   report += "<TD>" + mhs.size() + "X</TD>";
								   for(TblQLDTTXAHocVienHocPhiMonHoc mh : mhs)
									   hpX += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
								   countMonHoc[j] += mhs.size();
							   }
							   else
								   report += "<TD></TD>";
						   }
						   // Continue here
						   else {
							   if(mhs.size() > 0){
								   if (mhs.size() == 1)
									   report += "<TD>KM</TD>";
								   else
									   report += "<TD>" + mhs.size() + "KM</TD>";
								   //if(mh != null)
									//   hpKM += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
								   for(TblQLDTTXAHocVienHocPhiMonHoc mh : mhs)
									   if(mh.getTienTraLai() > 0){
										   hpKM += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
									   } else{
										   hpX += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
										   countMonHoc[j] += 1;
									   }
								   		
							   }
							   else
								   report += "<TD></TD>";
						   }						   
							   
					   }
					   if (donMienGiam == null)
						   donMienGiam = mienMon.getDonMGId();
				   }else
				   {				   					   
					   
					   /*if(mh != null){
						   report += "<TD>X</TD>";
						   hpX += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
						   countMonHoc[j] += 1;
					   }
					   else
						   report += "<TD></TD>";*/
					   if(mhs.size() > 0){
						   if (mhs.size() == 1)
							   report += "<TD>X</TD>";
						   else
							   report += "<TD>" + mhs.size() + "X</TD>";
						   for(TblQLDTTXAHocVienHocPhiMonHoc mh : mhs)
							   hpX += mh.getThanhTien() + quiDinhHocPhi.getTienHaTang();
						   countMonHoc[j] += mhs.size();
					   }
					   else
						   report += "<TD></TD>";
				   }
				   j++;
				   
				   
				   
			   }//end-for mon hoc

		      report += "<TD>" + myFormatter.format(hpX) + "</TD>";
		      countHPX += hpX;
		      
		      if(hpKM != 0){
			      report += "<TD>" + myFormatter.format(hpKM) + "</TD>";
			      countHPKM += hpKM;
		      } else {
		    	  report += "<TD> - </TD>";
		      }
		      
		      cons.clear();
			   { 
			       ConditionReport con = new ConditionReport(); 
			       con.setCol("hocVienId.id");
			       con.setValue1(hocVien.getId());
			       con.setOperator("eq");
			       cons.add(con);	
			   } 
			   List<TblQLDTTXAHocVienHocPhiBienLai> tblQLDTTXAHocVienHocPhiBienLais = tblQLDTTXAHocVienHocPhiBienLaiService.findtblQLDTTXAHocVienHocPhiBienLaiByCondition(cons, 0, 0);
			   Double tongTienDong = 0.0;
			   if (tblQLDTTXAHocVienHocPhiBienLais != null){
				   for(TblQLDTTXAHocVienHocPhiBienLai bienLai : tblQLDTTXAHocVienHocPhiBienLais){
					   tongTienDong += bienLai.getSoTien();
				   }
			   }
			   
			   if(donMienGiam != null){
				   report += "<TD>" + myFormatter.format(donMienGiam.getTongTienDong()) + "</TD>";
				   countTienMienMon += donMienGiam.getTongTienDong();
			   }else {
				   report += "<TD></TD>";
			   }
			   
			   report += "<TD>" + myFormatter.format(tongTienDong) + "</TD>";
			   countDaDong += tongTienDong;
			   
			   Double no = hpX + hpKM - tongTienDong;
			   countNo += no;
			   
			   if(no > 0)
				   report += "<TD>" + myFormatter.format(no) + "</TD>";
			   else if (no < 0)
				   report += "<TD>(" + myFormatter.format(no*-1) + ")</TD>";
			   else
				   report += "<TD>-</TD>";
			   
			   report +=  "</tr> ";
			   
			   
		  }
		  report += "</tbody><tfoot><tr class='tableitem' > "; 
		  
	      report += "<TD></TD>";
	      report += "<TD></TD>";
	      report += "<TD></TD>";
	      report += "<td>Tổng cộng</td> ";
	      report += "<td></td> ";
	      report += "<td></td> ";
	      
	      for(i = 0; i < countMonHoc.length; i++){
	    	  report += "<TD>" + countMonHoc[i] + "</TD>";
	      }
	      report += "<TD>" + myFormatter.format(countHPX) + "</TD>";
	      report += "<TD>" + myFormatter.format(countHPKM) + "</TD>";
	      report += "<TD>" + myFormatter.format(countTienMienMon) + "</TD>";
	      report += "<TD>" + myFormatter.format(countDaDong) + "</TD>";
	      report += "<TD>" + myFormatter.format(countNo) + "</TD>";
	      report += "</tr></tfoot>";
  
		  return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Report tblQLDTTXABienNhanHoSo Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 }

public String getReport() {
	return report;
}

public void setReport(String report) {
	this.report = report;
}


public Long getHocKyId() {
	return hocKyId;
}
public void setHocKyId(Long hocKyId) {
	this.hocKyId = hocKyId;
}

public List<TblQLDTTXAHocKyTrongNam> getTblQLDTTXAHocKyTrongNams() {
	return tblQLDTTXAHocKyTrongNams;
}
public void setTblQLDTTXAHocKyTrongNams(
		List<TblQLDTTXAHocKyTrongNam> tblQLDTTXAHocKyTrongNams) {
	this.tblQLDTTXAHocKyTrongNams = tblQLDTTXAHocKyTrongNams;
}

public List<TblQLDTTXAChuongTrinhHocChiTiet> getTblQLDTTXAChuongTrinhHocChiTiets() {
	return tblQLDTTXAChuongTrinhHocChiTiets;
}

public void setMsg(Message msg) {
	this.msg = msg;
} 
public Long getKhoaId() {
	return khoaId;
}
public void setKhoaId(Long khoaId) {
	this.khoaId = khoaId;
}
public Long getNganhId() {
	return nganhId;
}
public void setNganhId(Long nganhId) {
	this.nganhId = nganhId;
}
public Long getKhoaHocId() {
	return khoaHocId;
}
public void setKhoaHocId(Long khoaHocId) {
	this.khoaHocId = khoaHocId;
}
public Long getChiNhanhId() {
	return chiNhanhId;
}
public void setChiNhanhId(Long chiNhanhId) {
	this.chiNhanhId = chiNhanhId;
}
public List<TblQLDTTXADMKhoa> getTblQLDTTXADMKhoas() {
	return tblQLDTTXADMKhoas;
}
public void setTblQLDTTXADMKhoas(List<TblQLDTTXADMKhoa> tblQLDTTXADMKhoas) {
	this.tblQLDTTXADMKhoas = tblQLDTTXADMKhoas;
}

public List<TblQLDTTXADMNganh> getTblQLDTTXADMNganhs() {
	return tblQLDTTXADMNganhs;
}
public void setTblQLDTTXADMNganhs(List<TblQLDTTXADMNganh> tblQLDTTXADMNganhs) {
	this.tblQLDTTXADMNganhs = tblQLDTTXADMNganhs;
}
public List<TblQLDTTXADMKhoaHoc> getTblQLDTTXADMKhoaHocs() {
	return tblQLDTTXADMKhoaHocs;
}
public void setTblQLDTTXADMKhoaHocs(
		List<TblQLDTTXADMKhoaHoc> tblQLDTTXADMKhoaHocs) {
	this.tblQLDTTXADMKhoaHocs = tblQLDTTXADMKhoaHocs;
}
public List<TblQLDTTXADMChiNhanh> getTblQLDTTXADMChiNhanhs() {
	return tblQLDTTXADMChiNhanhs;
}
public void setTblQLDTTXADMChiNhanhs(
		List<TblQLDTTXADMChiNhanh> tblQLDTTXADMChiNhanhs) {
	this.tblQLDTTXADMChiNhanhs = tblQLDTTXADMChiNhanhs;
}
 } 
 
